SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE procedure dbo.DnnProduct_GetVendor

@VendorId int,
@PortalID int

as

select dbo.DnnProduct_Vendors.VendorName, 
       dbo.DnnProduct_Vendors.Unit, 
       dbo.DnnProduct_Vendors.Street, 
       dbo.DnnProduct_Vendors.City, 
       dbo.DnnProduct_Vendors.Region, 
       dbo.DnnProduct_Vendors.Country, 
       dbo.DnnProduct_Vendors.PostalCode, 
       dbo.DnnProduct_Vendors.Telephone,
       dbo.DnnProduct_Vendors.Fax,
       dbo.DnnProduct_Vendors.Cell,
       dbo.DnnProduct_Vendors.Email,
       dbo.DnnProduct_Vendors.Website,
       dbo.DnnProduct_Vendors.FirstName,
       dbo.DnnProduct_Vendors.LastName,
       dbo.DnnProduct_Vendors.ClickThroughs,
       dbo.DnnProduct_Vendors.Views,
       'CreatedByUser' = dbo.DnnProduct_Users.FirstName + ' ' + dbo.DnnProduct_Users.LastName,
       dbo.DnnProduct_Vendors.CreatedDate,
      'LogoFile' = case when dbo.DnnProduct_Files.FileName is null then dbo.DnnProduct_Vendors.LogoFile else dbo.DnnProduct_Files.Folder + dbo.DnnProduct_Files.FileName end,
       dbo.DnnProduct_Vendors.KeyWords,
       dbo.DnnProduct_Vendors.Authorized,
       dbo.DnnProduct_Vendors.PortalId
from dbo.DnnProduct_Vendors
left outer join dbo.DnnProduct_Users on dbo.DnnProduct_Vendors.CreatedByUser = dbo.DnnProduct_Users.UserId
left outer join dbo.DnnProduct_Files on dbo.DnnProduct_Vendors.LogoFile = 'fileid=' + convert(varchar,dbo.DnnProduct_Files.FileID)
where  VendorId = @VendorId
and    ((dbo.DnnProduct_Vendors.PortalId = @PortalID) or (dbo.DnnProduct_Vendors.PortalId is null and @PortalID is null))









GO
